import React, {Component} from 'react';
import './Footer.css'

class Footer extends Component {

    // 全选与取消全选
    handleCheckAll = (event) => {
        this.props.checkAllTodo(event.target.checked)
    }

    handleDeleteAllDone = () => {
        this.props.deleteTodoDone();
    }

    render() {
        const {todos} = this.props
        const count = todos.length
        // 统计已经完成
        const isDone = todos.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0)

        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.handleCheckAll} checked={count === isDone && count > 0}/>
                </label>
                <span>
                <span>已完成{isDone}</span> / 全部{count}
                </span>
                <button onClick={this.handleDeleteAllDone} className="btn btn-danger">清除已完成任务</button>
            </div>
        );
    }
}

export default Footer;